<template>
    <div v-for="(i, f) in fileList">{{ f.name }}</div>
    <el-menu default-active="1">
        <el-menu-item index="1" @click="()=>{this.$router.push('/index')}">
            <template #title>
                <el-icon>
                    <House />
                </el-icon>
                <span>首页</span>
            </template>
        </el-menu-item>
        <el-sub-menu index="2">
            <template #title>
                <el-icon>
                    <Folder />
                </el-icon>
                <span>{{ username }}</span>
            </template>
            <el-menu-item :index="'1-' + (i + 1) + ''" v-for="(f, i) of fileList" @click="openDir(f)">
                {{ f.directory.directoryName }}</el-menu-item>
        </el-sub-menu>
    </el-menu>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            fileList: []
        }
    },
    computed: {
        username() {
            return this.$store.getters.getLoginUser.username;
        }
    },
    methods: {
        getData() {
            axios('http://localhost:8082/file/getDir?userId=' + this.$store.getters.getLoginUser.id)
                .then(res => {
                    if (res.data.code === 1) {

                        this.fileList = res.data.data
                        console.log(this.fileList);
                    }
                }
                ).catch(err => {
                    console.log(err);
                });
        },
        openDir(f) {
            console.log(f);
            this.$router.push('/index/file');
            this.$store.commit('setCurDir', f.directory);
            sessionStorage.setItem('curDir', JSON.stringify(f.directory));
        }
    },
    mounted() {
        this.getData()
    }
}
</script>